// packageD/pages/promoteOrders/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pageIndex:1,
    pageCount:10,
    activeTab: 0,
    commissions:[],
    searchKey: '',
    totalOrders: 1266,
    totalAmount: '￥31,255',
    customDate: new Date().getTime(),
    orders: [
      // 示例数据
      {
        buyerName: '李*霸',
        mobile: '138****8888',
        commission: '¥5.6元',
        productImg: '/images/微分销.png',
        productName: '积分500',
        price: '¥500',
        quantity: 1,
        orderTime: '2022-10-25 12:32:45'
      },
      {
        buyerName: '李*霸',
        mobile: '138****8888',
        commission: '¥5.6元',
        productImg: '/images/微分销.png',
        productName: '积分500',
        price: '¥500',
        quantity: 1,
        orderTime: '2022-10-25 12:32:45'
      },
      {
        buyerName: '李*霸',
        mobile: '138****8888',
        commission: '¥5.6元',
        productImg: '/images/微分销.png',
        productName: '积分500',
        price: '¥500',
        quantity: 1,
        orderTime: '2022-10-25 12:32:45'
      },
      {
        buyerName: '李*霸',
        mobile: '138****8888',
        commission: '¥5.6元',
        productImg: '/images/微分销.png',
        productName: '积分500',
        price: '¥500',
        quantity: 1,
        orderTime: '2022-10-25 12:32:45'
      },
      {
        buyerName: '李*霸',
        mobile: '138****8888',
        commission: '¥5.6元',
        productImg: '/images/微分销.png',
        productName: '积分500',
        price: '¥500',
        quantity: 1,
        orderTime: '2022-10-25 12:32:45'
      },
      {
        buyerName: '李*霸',
        mobile: '138****8888',
        commission: '¥5.6元',
        productImg: '/images/微分销.png',
        productName: '积分500',
        price: '¥500',
        quantity: 1,
        orderTime: '2022-10-25 12:32:45'
      },
      // 更多订单数据...
    ],
    filteredOrders: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    // this.filterOrders();
this.showorders(this.data.pageIndex);
  },
  showorders(pageIndex){
    let param = {
      pageIndex,
      pageCount: 10
      // StartTime: start,
      // EndTime: end
    }
    this.GetCommissionDetail(param).then((res) => {
      if (res.data.value) {
        console.log(res.data.value)
        this.setData({
          commissions: res.data.value
        })
      }
    });
  },
   //获取分销订单
   GetCommissionDetail(param) {
    return wx.Http.post("/CommissionAppService/GetCommissionOrders",
      param
    );
  },
// 搜索处理
onSearch(e) {
  this.setData({ searchKey: e.detail });
  this.filterOrders();
},

// 选项卡切换
onTabClick(e) {
  this.setData({ activeTab: e.detail.index });
  this.filterOrders();
},

// 自定义时间选择
onConfirmDate(e) {
  this.setData({ customDate: e.detail });
  this.filterOrders();
},

// 订单过滤逻辑
filterOrders() {
  const { activeTab, searchKey, orders } = this.data;
  debugger
  let filtered = [...orders];

  // 时间过滤逻辑
  // 此处需要根据实际时间处理逻辑实现
  switch(activeTab) {
    case 1: // 今日
      break;
    case 2: // 昨日
      break;
    case 3: // 近7天
      break;
    case 4: // 自定义
      break;
  }

  // 搜索过滤
  if (searchKey) {
    filtered = filtered.filter(item => 
      item.buyerName.includes(searchKey) || 
      item.mobile.includes(searchKey)
    );
  }

  this.setData({ filteredOrders: filtered });
},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    
    this.showorders(1);
    this.setData({
      pageIndex:1
    })
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    if(this.data.commissions.count>this.data.pageIndex*10)
    {
this.showorders(this.data.pageIndex+1);
    this.setData({
      pageIndex:this.data.pageIndex+1
    })
    }
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})